var validar = new Array();



function validarNombre(){
    var comprobar=document.getElementById("nombre"); 
    nom=comprobar.value;
    if(/^([a-z]|[A-Z])+$/.test(nom)){
        comprobar.className="correcto";
        validar[0]=1;
    }else{
        comprobar.className="incorrecto";
        validar[0]=0;
    }

}


function validarApellido(){
    var comprobar=document.getElementById("apellido"); 
    apelli=comprobar.value;
    if(/^([a-z]|[A-Z]|\s)+$/.test(apelli)){
        comprobar.className="correcto";
        validar[1]=1;
    }else{
        comprobar.className="incorrecto";
        validar[1]=0;
    }

}

function validarTelefono(){
    var comprobar=document.getElementById("telefono"); 
    tlf=comprobar.value;
    if(/^([0-9]{9})+$/.test(tlf)){
        comprobar.className="correcto";
        validar[2]=1;
    }else{
        comprobar.className="incorrecto";
        validar[2]=0;
    }

}


function validarMail(){
    var comprobar=document.getElementById("mail"); 
    email=comprobar.value;
    if(/^(\w)+@(\w)+\.([a-z]{3})$/.test(email)){
        comprobar.className="correcto";
        validar[3]=1;
    }else{
        comprobar.className="incorrecto";
        validar[3]=0;
    }

}


function validarDni()
{
    var comprobar=document.getElementById("dni"); 
    d=comprobar.value;
    if(!(/^\d{8}[A-Z]$/.test(d))){
        
        comprobar.className="incorrecto";
        validar[4]=0;
    }else{
        comprobar.className="correcto";
        validar[4]=1;
    }
}



/*function validarDireccion(){
    var comprobar=document.getElementById("direccion"); 
    direcc=comprobar.value;
    if(/^([a-z]|[A-Z]|[0-9]|\s)+$/.test(direcc)){
        comprobar.className="correcto";
        validar[5]=1;
    }else{
        comprobar.className="incorrecto";
        validar[5]=0;
    }

}
*/
function validarFecha(){
    var comprobar=document.getElementById("fecha"); 
    fech=comprobar.value;
    if(/^(\d{2,4}\/\d{1,2}\/\d{1,2})+$/.test(fech)){
        comprobar.className="correcto";
		
        validar[5]=1;
    }else{
        comprobar.className="incorrecto";
        validar[5]=0;
    }

}

function validarNick(num){
    var comprobar=document.getElementById("nick"); 
    nom=comprobar.value;
    if(/^[\s-\w ñÑ]*$/.test(nom)){
        comprobar.className="correcto";
        validar[6]=1;
    }else{
        comprobar.className="incorrecto";
        validar[6]=0;
    }
	
	if(num==0){
		comprobar.className="incorrecto";
		//alert("aaaaaaa");
		validar[6]=0;
	}else{
	comprobar.className="correcto";
	//alert("bbbbbbb");
	validar[6]=1;
	}

}

function validarPwd(){
	var comprobar=document.getElementById("pwd");
	pwd=comprobar.value;
	
	if(/^(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{8,15})$/.test(pwd)){ //expresion regular: Entre 8 y 15 caracteres, por lo menos un digito y un alfanumérico, y no puede contener caracteres espaciales
		comprobar.className="correcto";
        validar[7]=1;
    }else if(/^!{8,15}$/.test(pwd)){
        comprobar.className="incorrecto";
        validar[7]=0;
    }else{
		comprobar.className="incorrecto";
        validar[7]=0;
	}
	
}



function validarPwd2(){
	var comprobar=document.getElementById("pwd2");
	var comprobar2=document.getElementById("pwd");
	pwd2=comprobar.value;
	pwd=comprobar2.value;
	
	var ok=document.getElementById("pwdok");
	var fail=document.getElementById("pwdfail");
	
	ok.className="oculto";
	fail.className="oculto";
	
	if(pwd2==pwd){ 
		ok.className="visible";
		comprobar.className="correcto";
		
        validar[8]=1;
    }else{
        fail.className="visible";
		comprobar.className="incorrecto";
        validar[8]=0;
    }
	
}

function validarArray(){
    var comprobar=document.getElementById("boton");
     
    for(cont=0;cont<validar.length;cont++){
        if(validar[cont]!=1){
            comprobar.className="oculto";
            return(true);
            
            
        }else if((validar[cont]==1)&&(cont==8)){
            
            comprobar.className="visible";
            
            return(true);
        }
        else{}
            
    }
    
}



//---------------------------------------
//----------------COOKIE-----------------
//---------------------------------------

/*
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
  {

  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}

function setCookie(c_name,exdays)
{  
value = document.getElementById("nick").value;
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function checkCookie()
{
var username=getCookie("username");

if (username!=null && username!="")
  {
  formulario = document.getElementById("form");
  formulario.className="oculto";
  var parrafo = document.createElement("p");
  var barrukoa = document.createTextNode("Bienvenido "+username);
  parrafo.appendChild(barrukoa);
  document.body.appendChild(parrafo);
   
  var boton = document.createElement("input");
  boton.type= "button";
  boton.value="exit";
  boton.onclick=deleteCookie;
  document.body.appendChild(boton);
  
  }
else
  {
      alert("No te has logeado");
      formulario = document.getElementById("form");
      formulario.className="visible";
  }
}




//----------------------------------

function deleteCookie(){
    
    value = "borrar";
    c_name = "username";
    exdays=-1;
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value=escape(value) + ((exdays==null) ? "" : ";expires="+exdate.toUTCString());
    document.cookie=c_name + "=" + c_value;
    
}
*/